﻿#ifndef EMQXCONTROLLER_H
#define EMQXCONTROLLER_H

#include <QObject>
#include <QProcess>
#include <QString>
#include <QEventLoop>
class EmqxController : public QObject
{
    Q_OBJECT

public:
    explicit EmqxController(QObject *parent = nullptr);
    ~EmqxController();

    enum Status {
        Unknown,
        Running,
        Stopped,
        Starting,
        Stopping
    };

    Status getStatus();
    bool start();
    bool stop();
    bool restart();
    bool install();
    bool uninstall();

    QString getOutput() const; // 获取最近一次输出
    QString getError() const;

signals:
    void outputReceived(const QString &output);
    void errorReceived(const QString &error);
    void statusChanged(Status status);

private:
    QString emqxPath; // 如 C:/emqx
    QProcess *process;
    Status currentStatus;
    QString stateoutstrings;
    QString startBack;
    QString stopBack;
    QString restartBack;

    void runCommand(const QStringList &args);
    void updateStatus();
};

#endif // EMQXCONTROLLER_H
